package com.gzr.demo01.threadestate;

//观察测试线程状态
public class TestState{
    public static void main(String[] args) {
        Thread thread = new Thread(()->{
            for (int i = 0; i < 1; i++) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("停止");
        });

        //观察线程状态
        Thread.State state = thread.getState();
        System.out.println(state);

        //启动后
        thread.start();
        state = thread.getState();

        //只要线程不停止就一直输出
        while (state != Thread.State.TERMINATED) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            state = thread.getState();
            System.out.println(state);
        }
    }

}
